package com.avitrix.learn.service;

import java.util.ArrayList;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import com.avitrix.learn.vo.BookList;
import com.avitrix.learn.vo.BookListInfo;
import com.avitrix.learn.vo.BookListResponse;
import com.avitrix.learn.vo.LoginApplicationRequest;
import com.avitrix.learn.vo.LoginApplicationResponse;
import com.avitrix.misc.UICLUtils;

@Path("/rest")
public class LearnService {

	@GET
	@Path("/loginService")
	@Produces("application/json")
	public LoginApplicationResponse loginAction(
			@QueryParam("username") @DefaultValue("") String userName,
			@QueryParam("password") @DefaultValue("") String password) {
	
		LoginApplicationRequest request = new LoginApplicationRequest();
		request.setUserName(userName);
		request.setPassword(password);
		LoginApplicationResponse applicationResponse = new LoginApplicationResponse();
		if(userName.equals("anoop") && password.equals("admin")){
			applicationResponse.setLoginStatus(true);
			applicationResponse.setName("Anoop R");
		} else {
			applicationResponse.setLoginStatus(false);
		}
		return applicationResponse;
	}
	
	@GET
	@Path("/getBooksList")
	@Produces("application/json")
	public BookListResponse loginAction(
			@QueryParam("username") @DefaultValue("") String userName) {
	
		BookList bookList = new BookList();
		ArrayList<BookListInfo> bookListInfos = new ArrayList<BookListInfo>();
		String url = UICLUtils.getContextVar("SERVERHost") + 
				":" + UICLUtils.getContextVar("SERVERPort") +
				"/" + UICLUtils.getContextVar("appContextName") +
				UICLUtils.getContextVar("PDFLocation");
		
		BookListResponse bookListResponse = new BookListResponse();
		BookListInfo bookListInfo = new BookListInfo();
		
		bookListInfo.setBookName("Life of Pi Film");
		bookListInfo.setAuthor("Yann Martel");
		bookListInfo.setUrl(url + "319970.pdf");
		bookListInfos.add(bookListInfo);
		
		bookListInfo = new BookListInfo();
		bookListInfo.setBookName("Life Is What You Make It ");
		bookListInfo.setAuthor("Preeti Shenoy");
		bookListInfo.setUrl(url + "319970.pdf");
		bookListInfos.add(bookListInfo);
		
		bookList.setBookListInfo(bookListInfos);
		bookListResponse.setBookList(bookList);
		return bookListResponse;
	}
}

